package routes

import (
	"GIN-API/internal/handlers"
	"GIN-API/internal/middleware"
	"GIN-API/internal/routes/api"
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
)

func Routes(r *gin.Engine) {
	r.GET("/ping", handlers.Ping)
	// Casbin 策略管理接口
	r.POST("/add-policy", handlers.AddPolicy)

	// 配置CORS中间件
	config := cors.DefaultConfig()
	config.AllowAllOrigins = true
	config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}
	config.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "Authorization"}
	r.Use(cors.New(config))

	// 登录注册路由
	api.InitAuthRouter(r)
	// 需要认证的路由
	protectedRoutes := r.Group("/")
	protectedRoutes.Use(middleware.AuthMiddleware())
	api.InitUserRouter(protectedRoutes)
	api.InitChannelRouter(protectedRoutes)
	api.InitArticleRouter(protectedRoutes)
	api.InitUploadRouter(protectedRoutes)
	protectedRoutes.GET("/dashboard", handlers.Dashboard)

}
